package com.supermarket.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.log.annotation.Log;
import com.supermarket.common.log.enums.BusinessType;
import com.supermarket.common.security.annotation.RequiresPermissions;
import com.supermarket.product.domain.ProductBrand;
import com.supermarket.product.service.IProductBrandService;
import com.supermarket.common.core.web.controller.BaseController;
import com.supermarket.common.core.web.domain.AjaxResult;
import com.supermarket.common.core.utils.poi.ExcelUtil;
import com.supermarket.common.core.web.page.TableDataInfo;

/**
 * 品牌信息Controller
 * 
 * @author      
 * @date 2025-07-20
 */
@RestController
@RequestMapping("/brand")
public class ProductBrandController extends BaseController
{
    @Autowired
    private IProductBrandService productBrandService;

    /**
     * 查询品牌信息列表
     */
    @RequiresPermissions("product:brand:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductBrand productBrand)
    {
        startPage();
        List<ProductBrand> list = productBrandService.selectProductBrandList(productBrand);
        return getDataTable(list);
    }
    /**
     * 查询品牌名称下拉
     */
    @GetMapping("/brankNameListXls")
    public AjaxResult brankNameListXls()
    {
        List<ProductBrand> list = productBrandService.brankNameListXls();
        return AjaxResult.success(list);
    }

    /**
     * 导出品牌信息列表
     */
    @RequiresPermissions("product:brand:export")
    @Log(title = "品牌信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductBrand productBrand)
    {
        List<ProductBrand> list = productBrandService.selectProductBrandList(productBrand);
        ExcelUtil<ProductBrand> util = new ExcelUtil<ProductBrand>(ProductBrand.class);
        util.exportExcel(response, list, "品牌信息数据");
    }

    /**
     * 获取品牌信息详细信息
     */
    @RequiresPermissions("product:brand:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productBrandService.selectProductBrandById(id));
    }

    /**
     * 新增品牌信息
     */
    @RequiresPermissions("product:brand:add")
    @Log(title = "品牌信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductBrand productBrand)
    {
        return toAjax(productBrandService.insertProductBrand(productBrand));
    }

    /**
     * 修改品牌信息
     */
    @RequiresPermissions("product:brand:edit")
    @Log(title = "品牌信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductBrand productBrand)
    {
        return toAjax(productBrandService.updateProductBrand(productBrand));
    }

    /**
     * 删除品牌信息
     */
    @RequiresPermissions("product:brand:remove")
    @Log(title = "品牌信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productBrandService.deleteProductBrandByIds(ids));
    }

}
